<template>
  <header class="header">
    <h1>todos</h1>
    <input id="toggle-all" class="toggle-all" v-model="isAll" type="checkbox" />
    <label for="toggle-all"></label>
    <input
      v-model.trim="task"
      class="new-todo"
      placeholder="输入任务名称-回车确认"
      autofocus
      @keyup.enter="keyupEnter"
    />
  </header>
</template>

<script>
export default {
  props: ["arr"],
  data() {
    return {
      task: "",
    };
  },
  computed: {
    isAll: {
      get() {
        return this.arr.every((item) => item.isDone);
      },
      set(val) {
        this.arr.forEach((item) => (item.isDone = val));
      },
    },
  },
  methods: {
    keyupEnter() {
      //调用父组件自定义添加事件
      this.task !== "" && this.$emit("add", this.task);
      this.task = "";
    },
  },
};
</script>
